﻿using System.Collections.Generic;
using System.Linq;
using Loki.Game;
using Loki.Game.GameData;
using Loki.Game.Inventory;

namespace FlaskHelper
{
    class Flasks
    {

        #region FlasksInit

        public static IEnumerable<InventoryItem> LifeFlasks
        {
            get
            {
                return from item in LokiPoe.PlayerInventory.Flasks.Items
                       let flask = item.Flask
                       where flask != null /*&& flask.Rarity != Rarity.Unique*/ && flask.HealthRecover > 0 && flask.CanUse
                       orderby flask.IsInstantRecovery ? flask.HealthRecover : flask.HealthRecoveredPerSecond descending
                       select item;
            }
        }

        public static IEnumerable<InventoryItem> ManaFlasks
        {
            get
            {
                return from item in LokiPoe.PlayerInventory.Flasks.Items
                       let flask = item.Flask
                       where flask != null /*&& flask.Rarity != Rarity.Unique*/ && flask.ManaRecover > 0 && flask.CanUse
                       orderby flask.IsInstantRecovery ? flask.ManaRecover : flask.ManaRecoveredPerSecond descending
                       select item;
            }
        }

        public static IEnumerable<InventoryItem> GraniteFlasks
        {
            get
            {
                return from item in LokiPoe.PlayerInventory.Flasks.Items
                       let flask = item.Flask
                       where flask != null && item.Name == "Granite Flask" && flask.CanUse
                       select item;
            }
        }

        public static IEnumerable<InventoryItem> JadeFlasks
        {
            get
            {
                return from item in LokiPoe.PlayerInventory.Flasks.Items
                       let flask = item.Flask
                       where flask != null && item.Name == "Jade Flask" && flask.CanUse
                       select item;
            }
        }

        public static IEnumerable<InventoryItem> RubyFlasks
        {
            get
            {
                return from item in LokiPoe.PlayerInventory.Flasks.Items
                       let flask = item.Flask
                       where flask != null && item.Name == "Ruby Flask" && flask.CanUse
                       select item;
            }
        }
        
        public static IEnumerable<InventoryItem> DiamondFlasks
        {
            get
            {
                return from item in LokiPoe.PlayerInventory.Flasks.Items
                       let flask = item.Flask
                       where flask != null && item.Name == "Diamond Flask" && flask.CanUse
                       select item;
            }
        }

        public static IEnumerable<InventoryItem> QuicksilverFlasks
        {
            get
            {
                //InternalName: flask_utility_sprint, BuffType: 24, CasterId: 13848, OwnerId: 0, TimeLeft: 00:00:05.0710000, Charges: 1, Description: You have greatly increased Movement Speed
                return from item in LokiPoe.PlayerInventory.Flasks.Items
                       let flask = item.Flask
                       where flask != null && item.Name == "Quicksilver Flask" && flask.CanUse
                       select item;
            }
        }

        public static IEnumerable<InventoryItem> BleedingFlasks
        {
            get
            {

                return from item in LokiPoe.PlayerInventory.Flasks.Items
                       let flask = item.Flask
                       where flask != null && item.Item.ExplicitStats.ContainsKey(StatType.LocalFlaskRemoveBleedingOnUse) && flask.CanUse
                       select item;
            }
        }

        public static IEnumerable<InventoryItem> ShockFlasks
        {
            get
            {
                return from item in LokiPoe.PlayerInventory.Flasks.Items
                       let flask = item.Flask
                       where flask != null && item.Item.ExplicitStats.ContainsKey(StatType.LocalFlaskRemoveShockOnUse) && flask.CanUse
                       select item;
            }
        }

        public static IEnumerable<InventoryItem> BurningFlasks
        {
            get
            {
                return from item in LokiPoe.PlayerInventory.Flasks.Items
                       let flask = item.Flask
                       where flask != null && item.Item.ExplicitStats.ContainsKey(StatType.LocalFlaskDispelsBurning) && flask.CanUse
                       select item;
            }
        }

        public static IEnumerable<InventoryItem> FrozenFlasks
        {
            get
            {
                return from item in LokiPoe.PlayerInventory.Flasks.Items
                       let flask = item.Flask
                       where flask != null && item.Item.ExplicitStats.ContainsKey(StatType.LocalFlaskDispelsFreezeAndChill) && flask.CanUse
                       select item;
            }
        }

        public static IEnumerable<InventoryItem> DivinationDistillate
        {
            get
            {
                return from item in LokiPoe.PlayerInventory.Flasks.Items
                       let flask = item.Flask
                       where flask != null && item.FullName == "Divination Distillate" && flask.CanUse
                       select item;
            }
        }

        #endregion

        #region Misc

        public static List<string> FlaskAuras = new List<string>
                                                    {
            "flask_effect_life",
            "flask_effect_mana",
            "flask_utility_ironskin",
            "flask_effect_jade",
            "flask_utility_resist_fire",
            "", // TODO : find the aura corresponding to diamond flasks
            "puncture",
            "shocked",
            "ignited",
            "chilled",
            "unique_flask_divination_distillate",
        };

        public enum FlaskTypes
        {
            Life = 0,
            Mana = 1,
            Granite = 2,
            Jade = 3,
            Ruby = 4,
            Diamond = 5,
            Bleeding = 6,
            Shock = 7,
            Burning = 8,
            Frozen = 9,
            Divination = 10
        }

        #endregion

    }
}
